//
//  MSRecommenProjectCell.m
//  SocietySale
//
//  Created by Mike on 16/12/2.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSRecommenProjectCell.h"

@interface MSRecommenProjectCell ()
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *typeLabel;
@property (nonatomic, strong) UILabel *stateLabel;
@property (nonatomic, strong) UILabel *addressLabel;
@property (nonatomic, strong) UILabel *positionLabel;
@property (nonatomic, strong) UIView  *bgView;
@end

@implementation MSRecommenProjectCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initView];
    }
    return self;
}

- (void)initView {
    self.titleLabel = [self creatLabel:CGRectMake(12, 10, SCREEN_WIDTH, 20)];
    self.titleLabel.font = HeitiFont(14);
    self.titleLabel.textColor = [UIColor blackColor];
    
    self.typeLabel = [self creatLabel:CGRectMake(12, self.titleLabel.bottom+8, SCREEN_WIDTH, 18)];
    self.typeLabel.textColor = kYellowColor;
    self.typeLabel.layer.borderColor = kYellowColor.CGColor;
    self.typeLabel.layer.borderWidth = 0.8;
    self.typeLabel.layer.cornerRadius = 2;
    self.typeLabel.textAlignment = NSTextAlignmentCenter;
    
    self.stateLabel = [self creatLabel:CGRectMake(0, self.titleLabel.bottom+7, SCREEN_WIDTH, 20)];
    self.addressLabel = [self creatLabel:CGRectMake(SCREEN_WIDTH -130, self.titleLabel.bottom+7, SCREEN_WIDTH, 20)];
    
    self.positionLabel = [self creatLabel:CGRectMake(12, self.addressLabel.bottom+5, SCREEN_WIDTH-24, 40)];
    self.positionLabel.numberOfLines = 0;
    
    _bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 100, SCREEN_WIDTH, 8)];
    _bgView.backgroundColor = kDefaultViewBackgroundColor;
    [self.contentView addSubview:_bgView];
    
    UIView *shortHorizonLineView =[[UIView alloc] initWithFrame:CGRectMake(12, _bgView.top-35, SCREEN_WIDTH-24, 0.6)];
    shortHorizonLineView.backgroundColor = kNormalGray;
    [self.contentView addSubview:shortHorizonLineView];
    
    UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.6)];
    horizonLineView.backgroundColor = kNormalGray;
    [_bgView addSubview:horizonLineView];
}

//创建label
- (UILabel*)creatLabel:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.font = HeitiFont(12);
    label.textColor = kDarkGrayColor;
    [self.contentView addSubview:label];
    return label;
}

- (void)setModel:(MSProjectModel *)model{
    _model = model;
    self.titleLabel.text = model.title;
    self.typeLabel.text = model.projectType;
    CGSize typeSize = [HDUtil getSizeWithText:model.projectType font:HeitiFont(14)];
    self.typeLabel.width = typeSize.width;
    
    self.stateLabel.left = self.typeLabel.right +5;
    self.stateLabel.text = [NSString stringWithFormat:@"%@  %@",model.projectState,model.investment];
    
    NSString *rightStr = [NSString stringWithFormat:@"%@",model.address];
    NSMutableAttributedString *addressAttstr = [[NSMutableAttributedString alloc] initWithString:rightStr attributes:@{NSFontAttributeName:HeitiFont(12),NSForegroundColorAttributeName:kDarkGrayColor}];
    
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    textAttachment.bounds = CGRectMake(0, -2.5, 14, 14);
    textAttachment.image = [UIImage imageNamed:@"loacation"];
    NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
    [addressAttstr insertAttributedString:attachmentString atIndex:0];
    
    self.addressLabel.attributedText = addressAttstr;
    
    NSMutableAttributedString *positionAttstr = [[NSMutableAttributedString alloc] initWithString:@"职位: "];
    NSAttributedString *positionStr = [[NSAttributedString alloc] initWithString:model.introduction attributes:@{NSForegroundColorAttributeName:kLightBlackColor}];
    NSAttributedString *timeStr = [[NSAttributedString alloc] initWithString:@"   时间: "];
    NSAttributedString *timeValue = [[NSAttributedString alloc] initWithString:model.time attributes:@{NSForegroundColorAttributeName:kLightBlackColor}];
    
    [positionAttstr appendAttributedString:positionStr];
    [positionAttstr appendAttributedString:timeStr];
    [positionAttstr appendAttributedString:timeValue];

    self.positionLabel.attributedText = positionAttstr;
}

@end
